<?php

$res = [7,3,6,5,2,65,23,12];

function qsort ($arr) {
	if(count($arr) <= 1) {
		return $arr;
	}
	$min = $arr[0];
	$left_arr = [];
	$right_arr = [];
	for ($i = 1;$i < count($arr); $i++) {
		if($arr[$i] <= $min) {
			$left_arr[] = $arr[$i];
		}else{
			$right_arr[] = $arr[$i];
		}
	}
	$left_arr = qsort($left_arr);
	$right_arr = qsort($right_arr);
	$new_arr = array_merge($left_arr,[$arr[0]],$right_arr);
	return $new_arr;

}

$a = qsort($res);
var_dump($a);
